<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\admin\logic\order;

use app\basic\BaseLogic;
use exception\ApiException;
use support\utils\Helper;
use app\admin\model\order\Order;

/**
 * 文档订单逻辑层
 */
class OrderLogic extends BaseLogic
{
    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->model = new Order();
    }

     /**
     * 分页查询数据
     * @return mixed
     */
    public function getListData($query)
    {
        $saiType = request()->input('saiType', 'list');
        $page = request()->input('page', 1);
        $limit = request()->input('limit', 10);
       $orderBy = request()->input('orderBy', 'order_id');
        $orderType = request()->input('orderType', 'desc');
        if ($this->scope) {
            $query = $this->userDataScope($query);
        }
        if(empty($orderBy)) {
            $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
        }
        $query->order($orderBy, $orderType);
        if ($saiType === 'all') {
            return $query->select()->toArray();
        }
        return $query->alias('o')
            ->join('eb_user_member um', 'o.user_id = um.id')
            ->join('eb_order_goods og', 'o.order_id = og.order_id')
            ->field('o.*, um.nickname, og.goods_name')
            ->paginate($limit, false, ['page' => $page])
            ->toArray();
    }


}
